package com.ohos.connent.accountcloud.biz.modular.dp.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ohos.connent.accountcloud.biz.modular.dp.entity.DpEnterpriseInfo;
import com.ohos.connent.accountcloud.biz.modular.dp.param.*;
import com.ohos.connent.accountcloud.biz.modular.dp.service.DpEnterpriseService;
import com.ohos.connent.accountcloud.biz.modular.dp.wrapper.DpEnterpriseDetailWrapper;
import com.ohos.connent.accountcloud.biz.modular.dp.wrapper.DpEnterprisePageWrapper;
import com.ohos.connent.accountcloud.biz.modular.dp.wrapper.DpEnterpriseRejectedWrapper;
import com.ohos.connent.accountcloud.common.annotation.CommonLog;
import com.ohos.connent.accountcloud.common.annotation.CommonWrapper;
import com.ohos.connent.accountcloud.common.pojo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author: ChenJiaHao
 * @Date: 2024/6/7 14:13
 * @Description:
 */
@Api(tags = "企业控制器")
@ApiSupport(author = "OHOSCONNECT_TEAM", order = 10)
@RestController
@Validated
@RequestMapping("/api/v1/account/dp/enterprise")
public class DpEnterpriseController {

    @Resource
    private DpEnterpriseService dpEnterpriseService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("企业界面列表")
    @CommonLog("企业界面列表")
    @PostMapping("/page")
    @CommonWrapper(value = DpEnterprisePageWrapper.class, isReplacement = true)
    public CommonResult<Page<DpEnterpriseInfo>> page(@RequestBody @Valid DpEnterprisePageParam dpEnterprisePageParam) {
        return CommonResult.data(dpEnterpriseService.page(dpEnterprisePageParam));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("添加企业认证")
    @CommonLog("添加企业认证")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid DpEnterpriseAddParam dpEnterpriseAddParam) {
        dpEnterpriseService.add(dpEnterpriseAddParam);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("企业认证明细")
    @CommonLog("企业认证明细")
    @GetMapping("/detail")
    @CommonWrapper(value = DpEnterpriseDetailWrapper.class, isReplacement = true)
    public CommonResult<DpEnterpriseInfo> detail(@Valid DpEnterpriseIdParam dpEnterpriseIdParam) {
        return CommonResult.data(dpEnterpriseService.queryEntity(dpEnterpriseIdParam.getId()));
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("修改企业认证")
    @CommonLog("修改企业认证")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid DpEnterpriseEditParam dpEnterpriseEditParam) {
        dpEnterpriseService.edit(dpEnterpriseEditParam);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("获取图片缩略图")
    @PostMapping("/getThumbnail")
    public CommonResult<String> getThumbnail(@RequestPart("file") MultipartFile file, DpEnterpriseThumbnailParam dpEnterpriseThumbnailParam){
         return CommonResult.data(dpEnterpriseService.getThumbnail(file, dpEnterpriseThumbnailParam));
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation("企业认证驳回")
    @CommonLog("企业认证驳回")
    @GetMapping("/rejected")
    @CommonWrapper(value = DpEnterpriseRejectedWrapper.class, isReplacement = true)
    public CommonResult<DpEnterpriseInfo> rejected(@Valid DpEnterpriseIdParam dpEnterpriseIdParam) {
        return CommonResult.data(dpEnterpriseService.queryEntity(dpEnterpriseIdParam.getId()));
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation("检测登录用户企业认证状态")
    @CommonLog("检测登录用户企业认证状态")
    @GetMapping("/check")
    public CommonResult<String> check() {
        return CommonResult.data(dpEnterpriseService.check());
    }
}
